package data_structure;

public class leetcode_0566 {
    public int[][] matrixReshape(int[][] mat, int r, int c) {
        int m=mat.length;
        int n=mat[0].length;
        if(m*n!=r*c) return mat;
        int []list=new int [m*n];
        int current=0;
        for(int i=0;i<m;++i){
            for(int j=0;j<n;++j){
                list[current]=mat[i][j];
                current++;
            }
        }
        current=0;
        int[][]ma=new int[r][c];
        for(int i=0;i<r;++i){
            for(int j=0;j<c;++j){
                ma[i][j]=list[current];
                current++;
            }
        }
        return ma;
    }
}
